package com.yaoli.niuke;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by will on 2017/5/10.
 */
public class _014_Test {
    public static void main(String[] args) {
        _014_Test test = new _014_Test();

        int [] aa = {1,2,3,4,5,6,7,0};

        test.InversePairs(aa);
    }
    public int InversePairs(int [] array) {

        //值 ： 位置   对
        Map<Integer,Integer> map = new HashMap<Integer,Integer>();

        for(int i = 0 ; i < array.length ; i++){
            map.put(array[i],i);
        }

        Arrays.sort(array);

        int count = 0;

        for(int i = 0 ; i < array.length ; i++){
            if(map.get(array[i]) < i){
                count = count + (i - map.get(array[i]));
            }
        }

        return count%1000000007 ;
    }
}
